//
//  ResultSendCompletedViewController.m
//  MobileChecker
//
//  Created by Lymons on 15-1-30.
//  Copyright (c) 2015年 Lymons. All rights reserved.
//

#import "ResultSendCompletedViewController.h"
#import "DiagnosisResultViewController.h"
#import "CheckResultItemViewModel.h"

@interface ResultSendCompletedViewController ()

@property (strong, nonatomic) IBOutlet UILabel *resultLabel;
@property (strong, nonatomic) IBOutlet UILabel *checkNumberLabel;
@property (strong, nonatomic) IBOutlet UILabel *shopCodeLabel;
@property (strong, nonatomic) IBOutlet UILabel *successLabel;
@property (weak, nonatomic) IBOutlet UIButton *priceButton;

@property (strong, nonatomic) CheckResultItemViewModel *viewModel;


@end

@implementation ResultSendCompletedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self bindViewModel];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.priceButton.hidden = ![CheckResultUserDefaults standardUserDefaults].shouldShowPriceButton;
    self.checkNumberLabel.text = self.checkNumberString;
    self.shopCodeLabel.text = self.shopCodeString;
    if (self.successString) {
        self.successLabel.text = self.successString;
        self.successLabel.hidden = NO;
    }
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.navigationController setViewControllers:@[self]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)bindViewModel
{
    self.viewModel = [[CheckResultItemViewModel alloc] init];
    RAC(self, resultLabel.text) = RACObserve(self, viewModel.resultString);
    RAC(self, resultLabel.textColor) = [RACObserve(self, resultLabel.text) map:^id(NSString *value) {
        return [CheckResultUserDefaults valueColor:value];
    }];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"DiagnosisPresent"]) {
        if ([segue.destinationViewController isKindOfClass:[DiagnosisResultViewController class]]) {
            DiagnosisResultViewController *vc = segue.destinationViewController;
            vc.hideBottomButton = YES;
        }
    }
}

@end
